package cn.silver.module.web.model;

import cn.silver.framework.web.enums.CaptchaTypeEnums;
import cn.silver.module.authority.bean.ClientBean;
import cn.silver.module.authority.bean.TenantBean;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * @author zhouxiaobo
 */
@Data
@NoArgsConstructor
@Schema(name = "AuthModel", description = "认证信息对象")
public class AuthModel implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;
    @Schema(title = "客户端主键")
    private String clientId;
    @Schema(title = "注册入口")
    private Boolean register;
    @Schema(title = "加密密钥")
    private String secret;
    @Schema(title = "租户访问开关")
    private Boolean tenant;
    @Schema(title = "验证码信息")
    private CaptchaModel captcha;
    @Schema(title = "租户列表")
    private List<TenantBean> tenants;
    @Schema(title = "授权类型")
    private Collection<String> grantTypes;

    public AuthModel(ClientBean model) {
        this.setClientId(model.getId());
        this.setSecret(model.getPublicKey());
        this.setRegister(model.getRegister());
        this.setGrantTypes(model.getGrantTypes());
        CaptchaModel captchaModel = new CaptchaModel();
        captchaModel.setEnable(!CaptchaTypeEnums.NONE.getCode().equalsIgnoreCase(model.getCaptcha()));
    }
}
